from random import random
from time import perf_counter
def calculate_pi():
    DARTS = 100000 * 10000
    hits = 0.0
    start = perf_counter()
    for i in range(DARTS):
        x, y = random(), random()
        dist = pow(x ** 2 + y ** 2, 0.5)
        if dist <= 1.0:
            hits = hits + 1
        if i%4e5==0:
            pi = 4 * (hits / (i+1))
            print("\r采样点数：{:<,15} 圆周率值是: {}".format(i+1,pi),end='')
            # print("运行时间是: {:.5f}s".format(perf_counter() - start))

if __name__=='__main__':
    calculate_pi()